export function StringBuilder(str){
    this.str = str || '';

    this.init = function(str){
        this.str = str;
        return this;
    };

    this.append = function(s){
        this.str += s;
        return this;
    };

    this.newLine = function(){
        this.str += "<br/>";
        return this;
    };

    this.indexOf = function(v){
        return this.str.indexOf(v);
    };

    this.endsWith = function(v){
        if('string' != typeof v)
            return false;
        return this.startsWith(v, this.str.length - v.length);
    };

    this.deleteCharAt = function(index){
        if(index < 0)
            return this;
        if(index >= this.str.length)
            return this;

        var tmp = this.str.substring(0,index) + this.str.substring(index + 1);
        this.str = tmp;
        return this;
    };

    this.deleteCharAtLast = function(){
        return this.deleteCharAt(this.str.length - 1);
    };

    this.deleteCharAtFirstt = function(){
        return this.deleteCharAt(0);
    };

    this.startsWith = function(v,idx){
        if('string' != typeof v){
            return false;
        }
        try{
            var tmp = this.str.substring(idx);
            return 0 === tmp.indexOf(v);
        }catch(E){console.log(E)}
        return 0 === this.str.indexOf(v);
    };

    this.charAt = function(v){
        return this.str.charAt(v);
    };

    this.replace = function(o,n){
        this.str = this.str.replace(o,n);
        return this.str;
    };

    this.toString = function(){
        return this.str;
    };
}